package com.weng.cloud.service8882.ribbon;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author: weng
 * @Date: 2022/3/5
 * @Description: com.weng.cloud.service8882.ribbon
 */
@RestController
@Slf4j
public class RibbonController {

    @Value("${server.port}")
    private String port;

    @RequestMapping(value="/timeout",method = RequestMethod.GET)
    public String timeout() {
        System.err.println("开始访问真实服务实例 => "+this.port);
        /*int i = 0;
        while(i ++ < 10){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.err.println("/timeout超时测试中【"+i+"】");
        }*/
        try {
//            Thread.sleep(600);
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "结束访问真实服务实例 => "+this.port;
    }

    @RequestMapping(value="/retry",method = RequestMethod.GET)
    public String retry(){
        log.info("/retry 开始执行 => "+this.port);

        int i = 5 / 0;

        return "/retry 执行结束 => "+this.port;
    }
}
